package doublepointer;

/**
 * @Classname : ValidPalindromeII
 * @Description : <a href="https://leetcode.cn/problems/valid-palindrome-ii/">680. 验证回文串 II</a>
 * @Author : chentianyu
 * @Date 2023/2/23 23:50
 */


public class ValidPalindromeII {
    public boolean validPalindrome(String s) {
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return judge(s, l+1, r) || judge(s, l, r-1);
            }
            l++;
            r--;
        }
        return true;

    }

    private boolean judge(String s, int l, int r) {
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) return false;
            l++;
            r--;
        }
        return true;
    }
}
